#include "data_es.hpp"
#include <thread>
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式， false-调试； true-发布");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");
DEFINE_string(es_host, "http://127.0.0.1:9200/", "es服务器URL");

int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    ChatSystem::InitLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto client = ChatSystem::EsClientFactory::create({FLAGS_es_host});
    auto es_msg = std::make_shared<ChatSystem::ESMessage>(client);
    // bool ret = es_msg->createIndex();
    // es_msg->appendData("uid1", "message_id1", 1748604448, "ssid1", "好厉害呀");
    // es_msg->appendData("uid2", "message_id2", 1748604448 - 50, "ssid1", "快点测试");
    // es_msg->appendData("uid3", "message_id3", 1748604448 - 100, "ssid1", "是否有错误");
    // es_msg->appendData("uid4", "message_id4", 1748604448 - 150, "ssid2", "朝我扔拧巴");
    // es_msg->appendData("uid5", "message_id5", 1748604448 - 200, "ssid2", "你礼貌吗？");


    std::this_thread::sleep_for(std::chrono::seconds(10));

    auto res = es_msg->search("好快是", "ssid1");
    for(auto& u : res)
    {
        std::cout << "------------------" << std::endl;
        std::cout << u.user_id() << std::endl;
        std::cout << u.session_id() << std::endl;
        std::cout << boost::posix_time::to_simple_string(u.create_time()) << std::endl;
        std::cout << *u.content() << std::endl;
        std::cout << u.message_id() << std::endl;
    }
}